import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)
// const routers = JSON.parse(localStorage.getItem('role')) || []
// console.log(routers, 'router');
// const children = (arr) => {
//   let list = [{
//     path: '/home/index',
//     component: () => import(`../views/home/index`)
//   }]
//   // arr.forEach((item, index) => {
//   //   return list.push({
//   //     path: item.path,
//   //     component: () => import(`../views/home/${item.path}/index.vue`)
//   //   })
//   // });
//   return list
// }
// console.log(children(), '11111');

const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    name: 'home',
    component: () => import('../views/home/home.vue'),
    children: [
      {
        path: '/home/index',
        name: 'index',
        component: () => import('../views/home/index'),
      },
      {
        path: '/home/auths',
        name: 'auths',
        component: () => import('../views/home/auths'),
        children: [
          {
            path: '/home/auths/cdauth',
            name: 'cdauth',
            component: () => import('../views/home/auths/cdauth'),
          },
          {
            path: '/home/auths/jsauth',
            name: 'jsauth',
            component: () => import('../views/home/auths/jsauth'),
          }
        ]
      },
      {
        path: '/home/system',
        name: 'system',
        component: () => import('../views/home/system'),
        children: [
          {
            path: '/home/system/fwsystem',
            name: 'fwsystem',
            component: () => import('../views/home/system/fwsystem'),
          },
          {
            path: '/home/system/dlsystem',
            name: 'dlsystem',
            component: () => import('../views/home/system/dlsystem'),
          }
        ]
      },
      {
        path: '/home/user',
        name: 'user',
        component: () => import('../views/home/user'),
        children: [
          {
            path: '/home/user/pzuser',
            name: 'pzuser',
            component: () => import('../views/home/user/pzuser'),
          },
          {
            path: '/home/user/bquser',
            name: 'bquser',
            component: () => import('../views/home/user/bquser'),
          }
        ]
      },
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login')
  }
]
// 下面都是必填，其它meta按需求添加      
// router.addRoute(children());
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,

})

export default router
